package com.liu.manager.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.liu.manager.bean.ResponseResult;
import com.liu.manager.entity.Sysuser;
import com.liu.manager.service.SysuserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/sysuser")
public class SysuserController {

    @Resource
    SysuserService service;

    @PostMapping(value = "/addUser",produces = {"application/json;charset=utf-8"})
    public String addUser(@RequestBody Sysuser sysuser){
        ResponseResult result = service.insertUser(sysuser);
        return JSON.toJSONString(result,JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @PostMapping(value = "/removeUserById",produces = {"application/json;charset=utf-8"})
    public String removeUserById(long id){
        ResponseResult result = service.deleteUser(id);
        return JSON.toJSONString(result,JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @PostMapping(value = "/updateUser",produces = {"application/json;charset=utf-8"})
    public String updateUser(@RequestBody Sysuser sysuser){
        ResponseResult result = service.updateUser(sysuser);
        return JSON.toJSONString(result,JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @GetMapping(value = "/getUserById",produces = {"application/json;charset=utf-8"})
    public String getUserById(long id){
        ResponseResult result = service.findById(id);
        return JSON.toJSONString(result,JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }
}
